home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / disk / cdrom / AmiCDROM_1_15.lha / AmiCDROM / src / intui.c < prev    next >
C/C++ Source or Header  |  1994-11-03  |  7KB  |  244 lines

  1. /* intui.c:
  2.  *
  3.  * System requester stuff.
  4.  *
  5.  * ----------------------------------------------------------------------
  6.  * This code is (C) Copyright 1993,1994 by Frank Munkert.
  7.  * All rights reserved.
  8.  * This software may be freely distributed and redistributed for
  9.  * non-commercial purposes, provided this notice is included.
  10.  * ----------------------------------------------------------------------
  11.  * History:
  12.  * 
  13.  * 18-Jul-94   fmu   - New CDDA icon (by Olivier Tonino)
  14.  *                   - User-definable icon
  15.  * 05-Jan-94   fmu   Retry displaying CD-DA icon if WB is not open.
  16.  * 02-Jan-94   fmu   Location for CD-DA icon may be defined by user.
  17.  * 11-Dec-93   fmu   Fixed AddAppIconA() call for DICE.
  18.  * 28-Nov-93   fmu   Added custom CD-DA icon; removed GetDefDiskObject() call.
  19.  * 09-Oct-93   fmu   SAS/C support added
  20.  */
  21.  
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24.  
  25. #include <exec/types.h>
  26. #include <intuition/intuition.h>
  27. #include <workbench/workbench.h>
  28. #include <workbench/startup.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <clib/intuition_protos.h>
  32. #include <clib/icon_protos.h>
  33. #include <clib/wb_protos.h>
  34.  
  35. #ifdef LATTICE
  36. #include <pragmas/exec_pragmas.h>
  37. #include <pragmas/intuition_pragmas.h>
  38. #include <pragmas/icon_pragmas.h>
  39. #include <pragmas/wb_pragmas.h>
  40. #endif
  41.  
  42. #include "intui.h"
  43.  
  44. struct IntuitionBase *IntuitionBase;
  45. struct Library *IconBase;
  46. struct Library *WorkbenchBase;
  47.  
  48. struct MsgPort *g_app_port;
  49. struct AppIcon *g_app_icon;
  50. ULONG g_app_sigbit;
  51. int g_retry_show_cdda_icon = FALSE;
  52.  
  53. USHORT g_image_data[] = {
  54.     /* Plane 0 */
  55.         0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x1D5F,0x5000,
  56.         0x0002,0x8000,0x0000,0x0002,0x8000,0x0000,0x001E,0xB9F1,0xF000,
  57.         0x0030,0xEF0F,0x1800,0x002E,0xAAF2,0xE800,0x002E,0xEEF6,0xB800,
  58.         0x002E,0xAB1A,0x8000,0x002E,0xA9EA,0xB800,0x002E,0xA9EA,0xE800,
  59.         0x0030,0xAA1B,0x1800,0x001F,0x39F1,0xF000,0x0000,0x0000,0x0000,
  60.         0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0003,0xFFAB,0x9110,
  61.         0x000F,0x04D5,0x6930,0x4430,0xAAAA,0x8BA4,0x0040,0x54D4,0x5440,
  62.         0x54A8,0x0AA8,0xA87C,0x0955,0x44D5,0x5448,0x52AA,0xA02A,0x8014,
  63.         0x22AA,0xA7D4,0x0062,0x5001,0x4D6A,0xAAD4,0xAAAA,0x07DF,0x554A,
  64.         0x5250,0x882F,0xFED4,0xB805,0x5717,0xFDFA,0x552A,0xAE0B,0xFBD4,
  65.         0xEF95,0x5C45,0xE3EE,0x5D62,0xB80A,0x1F5C,0xFFDD,0x5555,0xFBFE,
  66.         0x7777,0xF777,0xD776,0xFFFE,0xFFFE,0x7FFE,0xFFFF,0xFFFF,0xFFFE,
  67.     /* Plane 1 */
  68.         0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x140D,0x1000,
  69.         0x5455,0x4000,0x0454,0x0001,0x0000,0x0000,0x5541,0x6C04,0x0554,
  70.         0x888F,0x10F0,0xE088,0x555B,0x5505,0x1554,0xAA91,0x1171,0x02AA,
  71.         0x5551,0x54E5,0x5554,0xEED1,0x5595,0x46EE,0x555B,0x5415,0x1554,
  72.         0xFFCF,0x55E4,0xE7FE,0x5540,0x6C04,0x0554,0xFFFF,0xFFFF,0xFFFE,
  73.         0xDDDD,0xDDDD,0xDDDC,0xFFFF,0xFFFF,0xFFFE,0xFFFC,0x55FE,0x6EEE,
  74.         0xFFF6,0xAEFB,0xDEEE,0xBB9F,0xFFF7,0x755A,0xFFFF,0xBEEE,0xAFBE,
  75.         0xAAFF,0xF7DD,0x5FC2,0xF7FF,0xFABA,0xFFB6,0xA9FF,0xFFF7,0xFFEA,
  76.         0xDF55,0x583F,0xFFBC,0xAAAA,0xB6DF,0xFFAA,0x53F5,0xFBAA,0xAAD4,
  77.         0xABEF,0x7FF4,0x054A,0x45FB,0xFDFA,0x02C4,0xABDF,0xF9FD,0x0D2A,
  78.         0x10EF,0xF2BE,0xBA10,0xA2DD,0xE5F7,0xEAA2,0x0013,0xFAAB,0x4800,
  79.         0x8887,0x088A,0x4888,0x0000,0xD00A,0x8000,0x0000,0x0000,0x0000,
  80.     /* Plane 2 */
  81.         0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFE,0xFFFE,0xE2A0,0xAFFE,
  82.         0xFFFC,0x7FFF,0xFFFE,0xFFFC,0x7FFF,0xFFFE,0xFFE0,0x460E,0x0FFE,
  83.         0xFFD0,0x4505,0x17FE,0xFFC0,0x440C,0x07FE,0xFFC4,0x440C,0x47FE,
  84.         0xFFC4,0x4514,0x7FFE,0xFFC4,0x4604,0x47FE,0xFFC0,0x4604,0x07FE,
  85.         0xFFD0,0x4415,0x17FE,0xFFE0,0xC60E,0x0FFE,0xFFFF,0xFFFF,0xFFFE,
  86.         0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFAB,0xFFFE,
  87.         0xFFFF,0x51D5,0x7FFE,0xFFF0,0x00A8,0x8BBE,0xFFC0,0x41D1,0x547E,
  88.         0xFFA8,0x08A2,0xA87E,0xFF55,0x45C5,0x547E,0xFEAA,0xA02A,0x803E,
  89.         0xFEAA,0xA454,0x007E,0xFD55,0x4BAA,0xAAFE,0xFE0A,0x045F,0x553E,
  90.         0xFE10,0xA82F,0xFEBE,0xFE04,0x0357,0xFD3E,0xFE20,0x06AB,0xFA7E,
  91.         0xFF10,0x0D55,0xE4FE,0xFFA2,0x1AAA,0x11FE,0xFFED,0x5555,0x87FE,
  92.         0xFFF8,0xFFFC,0x3FFE,0xFFFF,0x0001,0xFFFE,0xFFFF,0xFFFF,0xFFFE
  93. };
  94.  
  95. struct Image g_disk_object_image = {
  96.   0, 0,            /* top corner */
  97.   47, 36, 3,        /* width, height, depth */
  98.   g_image_data,
  99.   0xff, 0x00,        /* planepick, planeonoff */
  100.   NULL,            /* next image */
  101. };
  102.  
  103. UBYTE *g_tool_types[] = {
  104.   NULL
  105. };
  106.  
  107. struct DiskObject *g_user_disk_object = NULL;
  108.  
  109. struct DiskObject g_disk_object = {
  110.   WB_DISKMAGIC,
  111.   WB_DISKVERSION,
  112.   {
  113.     NULL,
  114.     0, 0,
  115.     47, 37,
  116.     GADGIMAGE | GADGHCOMP,
  117.     RELVERIFY | GADGIMMEDIATE,
  118.     BOOLGADGET,
  119.     (APTR) &g_disk_object_image,
  120.     NULL,
  121.   },
  122.   0,
  123.   "",
  124.   (char **) g_tool_types,
  125.   NO_ICON_POSITION,
  126.   NO_ICON_POSITION,
  127.   NULL,
  128.   NULL,
  129.   0
  130. };
  131.  
  132. long g_xpos = NO_ICON_POSITION;
  133. long g_ypos = NO_ICON_POSITION;
  134.  
  135. char *g_iconname = "CD-DA";
  136.  
  137. void Init_Intui (void)
  138. {
  139.   IntuitionBase = (struct IntuitionBase *)
  140.      OpenLibrary ((UBYTE *) "intuition.library", 37);
  141.   IconBase = OpenLibrary ((UBYTE *) "icon.library", 37);
  142.   if (!IconBase)
  143.     Display_Error ("cannot open icon.library");
  144.   WorkbenchBase = OpenLibrary ((UBYTE *) "workbench.library", 37);
  145.   if (!WorkbenchBase)
  146.     Display_Error ("cannot open workbench.library");
  147.  
  148.   g_user_disk_object = GetDiskObject ("env:cdda");
  149.   if (!g_user_disk_object) {
  150.     g_user_disk_object = &g_disk_object;
  151.   } else {
  152.     char *name;
  153.     if (name = FindToolType (g_user_disk_object->do_ToolTypes, "ICONNAME"))
  154.       g_iconname = name;
  155.   }
  156.  
  157.   g_app_port = NULL;
  158.   g_app_sigbit = 0;
  159.   g_app_icon = NULL;
  160. }
  161.  
  162. void Close_Intui (void)
  163. {
  164.   if (WorkbenchBase)
  165.     CloseLibrary (WorkbenchBase);
  166.   if (IconBase)
  167.     CloseLibrary (IconBase);
  168.   if (IntuitionBase)
  169.     CloseLibrary ((struct Library *) IntuitionBase);
  170. }
  171.  
  172. void Display_Error (char *p_message, ...)
  173. {
  174.   va_list arg;
  175.  
  176.   static struct EasyStruct req = {
  177.     sizeof (struct EasyStruct),
  178.     0,
  179.     (UBYTE *) "CDROM Handler Error",
  180.     NULL,
  181.     (UBYTE *) "Abort"
  182.   };
  183.   
  184.   va_start (arg, p_message);
  185.   if (IntuitionBase) {
  186.     req.es_TextFormat = (UBYTE *) p_message;
  187.     EasyRequestArgs (NULL, &req, NULL, arg);
  188.   }
  189.   va_end (p_message);
  190. }
  191.  
  192. void Show_CDDA_Icon (void)
  193. {
  194.   if (!IconBase || !WorkbenchBase)
  195.     return;
  196.  
  197.   g_user_disk_object->do_CurrentX = g_xpos;
  198.   g_user_disk_object->do_CurrentY = g_ypos;
  199.  
  200.   if (g_app_icon)
  201.     Display_Error ("Show_CDDA_Icon called twice!");
  202.  
  203.   g_app_port = CreateMsgPort ();
  204.   if (!g_app_port)
  205.     return;
  206.  
  207.   g_app_sigbit = 1<<g_app_port->mp_SigBit;
  208.  
  209.   g_app_icon = AddAppIconA (0, 0, (UBYTE *) g_iconname, g_app_port,
  210.                   NULL, g_user_disk_object, NULL);
  211.  
  212.   /* AddAppIconA may fail if the Workbench has not yet been loaded.
  213.    */
  214.   if (!g_app_icon) {
  215.     DeleteMsgPort (g_app_port);
  216.     g_app_port = NULL;
  217.     g_retry_show_cdda_icon = TRUE;
  218.     return;
  219.   }
  220.   g_retry_show_cdda_icon = FALSE;
  221. }
  222.  
  223. void Hide_CDDA_Icon (void)
  224. {
  225.   struct Message *msg;
  226.  
  227.   g_retry_show_cdda_icon = FALSE;
  228.  
  229.   if (!IconBase || !WorkbenchBase)
  230.     return;
  231.  
  232.   if (g_app_icon)
  233.     RemoveAppIcon (g_app_icon);
  234.   if (g_app_port) {
  235.     while (msg = GetMsg (g_app_port))
  236.       ReplyMsg (msg);
  237.     DeleteMsgPort (g_app_port);
  238.   }
  239.  
  240.   g_app_port = NULL;
  241.   g_app_sigbit = 0;
  242.   g_app_icon = NULL;
  243. }
  244.